package com.ybl.store.backend.config;

import com.ybl.store.backend.interceptor.JwtTokenAdminInterceptor;
import com.ybl.store.backend.interceptor.JwtTokenClerkInterceptor;
import com.ybl.store.backend.interceptor.JwtTokenManagerInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * WebMvc 配置
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    private final JwtTokenAdminInterceptor jwtTokenAdminInterceptor;

    private final JwtTokenManagerInterceptor jwtTokenManagerInterceptor;

    private final JwtTokenClerkInterceptor jwtTokenClerkInterceptor;

    /**
     * 注册拦截器
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/store/**")
                .addPathPatterns("/manager/**");
        registry.addInterceptor(jwtTokenManagerInterceptor)
                .addPathPatterns("/clerk/**");
        registry.addInterceptor(jwtTokenClerkInterceptor)
                .addPathPatterns("/customer/**");
    }
}
